/*
 * @FilePath: \undefinedc:\Users\sxjct\.leetcode\46.全排列.cpp
 * @Brief: 
 * @Version: 1.0
 * @Date: 2021-03-05 10:54:23
 * @Author: tianyiyi
 * @Copyright: Copyright@tianyiyi
 * @LastEditors: Mr.Tian
 * @LastEditTime: 2021-03-22 15:37:51
 */
/*
 * @lc app=leetcode.cn id=46 lang=cpp
 *
 * [46] 全排列
 */

// @lc code=start
class Solution {
public:
    vector<vector<int>> res;
    void backtrace(vector<int>& nums,vector<int>& path,vector<bool> &used)
    {
        if(path.size() == nums.size())
        {
            res.push_back(path);
            return;
        }
        for(int i = 0 ; i < nums.size() ; i++)
        {
            if(used[i] == true)
            {
                continue;
            }
            path.push_back(nums[i]);
            used[i] = true;
            backtrace(nums,path,used);
            path.pop_back();
            used[i] = false;
        }
    }


    vector<vector<int>> permute(vector<int>& nums) {
        vector<int> path;
        vector<bool> used(nums.size(),false);
        backtrace(nums,path,used);
        return res;
    }
};
// @lc code=end

